package com.wish.g04.financing.controller;


import com.wish.g04.base.entity.CwDealPerDay;
import com.wish.g04.common.core.web.controller.BaseController;
import com.wish.g04.common.core.web.domain.AjaxResult;
import com.wish.g04.common.core.web.page.TableDataInfo;
import com.wish.g04.financing.dto.DealPerDayDTO;
import com.wish.g04.financing.dto.DealPerDayDetailsDTO;
import com.wish.g04.financing.service.DealPerDayService;
import com.wish.g04.financing.vo.DealPerDayTotalVO;
import com.wish.g04.financing.vo.DealPerDayDetailsVO;
import com.wish.g04.financing.vo.PaymentPlanTotalVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;


/**
 * 营业报表
 * @author tianyandong
 */
@RestController
@RequestMapping("/deal_per_day")
public class DealPerDayController extends BaseController {

    @Autowired
    private DealPerDayService dealPerDayService;


    /**
     * 查询营业报表信息
     * @param dealPerDayDTO
     * @return
     */
    @GetMapping("getDealPerDayList")
    public AjaxResult getDealPerDayList(DealPerDayDTO dealPerDayDTO) {
        startPage();
        //查询收入或支出数据
        List<CwDealPerDay> cwDealPerDayList = dealPerDayService.getDealPerDayList(dealPerDayDTO);
        //统计总额
        DealPerDayTotalVO dealPerDayTotalVO = dealPerDayService.getDealPerDaySum(dealPerDayDTO);
        TableDataInfo dataTable = getDataTable(cwDealPerDayList);
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",dataTable);
        map.put("total",dealPerDayTotalVO);
        return AjaxResult.success(map);
    }


    /**
     * 查询收入明细的详情
     * @return
     */
    @GetMapping("getReceiptPlanList")
    public AjaxResult getReceiptPlanList(DealPerDayDetailsDTO dealPerDayDetailsDTO) {
        startPage();
        //查询明细
        List<DealPerDayDetailsVO> receiptPlanVOList = dealPerDayService.getReceiptPlanList(dealPerDayDetailsDTO);
        //统计某天的收入总额
        BigDecimal totalSum = dealPerDayService.getReceiptPlanSum(dealPerDayDetailsDTO);
        TableDataInfo dataTable = getDataTable(receiptPlanVOList);
        HashMap<String, Object> map = new HashMap<>();
        map.put("receiptPlanVOList",dataTable);
        map.put("totalSum",totalSum);
        return AjaxResult.success(map);
    }

    /**
     * 查询支出明细的详情
     * @return
     */
    @GetMapping("getPaymentPlanList")
    public AjaxResult getPaymentPlanList(DealPerDayDetailsDTO dealPerDayDetailsDTO) {
        startPage();
        //查询明细
        List<DealPerDayDetailsVO> paymentPlanList = dealPerDayService.getPaymentPlanList(dealPerDayDetailsDTO);
        //统计某天的支出总额明细
        PaymentPlanTotalVO paymentPlanTotalVO = dealPerDayService.getPaymentPlanSum(dealPerDayDetailsDTO);
        TableDataInfo dataTable = getDataTable(paymentPlanList);
        HashMap<String, Object> map = new HashMap<>();
        map.put("paymentPlanList",dataTable);
        map.put("paymentPlanTotalVO",paymentPlanTotalVO);
        return AjaxResult.success(map);
    }


}
